{block name=body}

	<div class="row form-group">
		<div class="col-sm-6 col-sm-offset-3 text-center">
			<img src="/admin/images/logo.png" alt="" class="img-responsive" id="loginlogo" />
		</div>
	</div>
	<div class="row">
	<div class="col-sm-6 col-sm-offset-3 text-center" id="loginbox">
		<form id="login-form" accept-charset="UTF-8" method="post">
			<input type="hidden" value="{$redirect}" name="redirect" class="redirect" /> 
			<div class="row form-group">
				<label  class="col-sm-4 control-label" for="email">邮箱:</label>
				<div class="col-sm-8">
					<input type="email" class="form-control" name="email" id="email" class="text-box-login"  onblur="$('#reset-email').val( this.value )" required>
				</div>
			</div>
			<div class="row form-group">
				<label  class="col-sm-4 control-label" for="password" >密码:</label>
				<div class="col-sm-8 text-left">
					<input type="password" class="form-control" name="password" id="password" class="text-box-login-password" required>
					<span class="form-help-block"><a href="javascript:void(0)" onclick="$('#reset-pass').show('slow');$('#login-form').hide('slow');"><small>忘记密码?</small></a></span>
				</div>
			</div>
			<div class="col-sm-offset-4 error-alert" style="display:none;">
		    <div class="alert alert-danger fade in ">
					<button class="close" aria-hidden="true" type="button" onclick="$(this).closest('.error-alert').fadeOut('slow');">&times;</button>
					<strong></strong>
				</div>
		  </div>
			<div class="form-group">
				<div class="col-sm-4">
					<input type="hidden" name="formToken" id="formToken" value="{$token}" />
					<input type="hidden" value="login" name="action" id="action" /> 
				</div>
				<div class="col-sm-8 form-actions text-right">
					<button class="btn btn-default" type="submit" title="login">登陆</button>
				</div>
			</div>
		</form>
		
		
		<div id="reset-pass" style="display:none;"><!-- RESET PASSWORD SECTION - Hidden by default -->
		   <h3 class="text-center" id="reset-pass-title">重置密码</h3>
		   <form class="form-horizontal" id="reset-pass-form" data-attr-id="reset-pass-form" role="form" accept-charset="UTF-8" action="" method="post">
		     <input type="hidden" value="resetPassword" name="action" id="action" /> 
		     <input type="hidden" name="formToken" value="{$token}" />
		     
		        <div class="row">
		        
		        <div class="form-group">
		         <label for="email" class="col-sm-4 control-label">邮箱*:</label>
		         <div class="col-sm-8">
		         	<input type="email" value="" class="form-control" id="reset-email" name="email" required>
		         </div>
		         <span class="help-block"></span>
		     </div>
		     	<div class="col-sm-offset-4 error-alert" style="display:none;">
				    <div class="alert alert-danger fade in ">
							<button class="close" aria-hidden="true" type="button" onclick="$(this).closest('.error-alert').fadeOut('slow');">&times;</button>
							<strong></strong>
						</div>
				  </div>
		      <div class="col-sm-offset-4 success-alert" style="display:none;">
		      	<div class="alert alert-success fade in ">
							<button class="close" aria-hidden="true" type="button"  onclick="$(this).closest('.success-alert').fadeOut('slow');">&times;</button>
							<strong></strong>
						</div>
		      </div>
		     <div class="col-sm-12 form-group text-right">
		      <button type="button" class="btn btn-info" onclick="$('#reset-pass').hide('slow');$('#login-form').show('slow');">取消</button>
		      <button type="submit" class="btn btn-default">重置</button>
		     </div>
		      </div>
		   </form>
		 </div>
		</div>
	</div>
	<div id="log"></div>




<script src="/admin/includes/js/jquery.validate.min.js"></script>
<script type="text/javascript">
if (jQuery.validator) {
	  jQuery.validator.setDefaults({
	    errorClass: 'has-error',
	    validClass: 'has-success',
	    ignore: "",
	    highlight: function (element, errorClass, validClass) {
	      $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
	    },
	    unhighlight: function (element, errorClass, validClass) {
	      $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
	    },
	    errorPlacement: function (error, element) {
	     
	    },
	    submitHandler: function (form) {
	    	var formID = $(form).attr('id');
	    	Login(formID);
	    }
	  });
}

$(document).ready(function(){
	$('#login-form').validate({
		onkeyup: false
	});
	$('#reset-pass-form').validate({
		onkeyup: false
	});
});

function Login(formID){
	$('body').css('cursor', 'wait');
	$('.btn-primary').addClass('disabled');
	var datastring = $('#'+formID).serialize();
	$.ajax({
		type : "POST",
		url : "/admin/includes/processes/processes-login.php",
		cache : false,
		data : datastring,
		dataType : "html",
		success : function(data, textStatus) {
			try {
				var obj = $.parseJSON(data);
				if (obj.error) {
			 		$('#'+formID).find('.error-alert').find('strong').html(obj.error);
			 		$('#'+formID).find('.error-alert').fadeIn('slow'); 
			 	} else if (obj.success){
				 	if(formID == 'login-form')	location.assign(obj.redirect);
				 	$('#reset-pass').hide();
				 	$('#'+formID).find('.success-alert').find('strong').html(obj.error);
			 		$('#'+formID).find('.success-alert').fadeIn('slow'); 
			 	}
			} catch (err) {
			}
			$('body').css('cursor', 'default');
			$('.btn-primary').removeClass('disabled');
		},
		error: function(){
			$('body').css('cursor','default'); 
			$('.btn-primary').removeClass('disabled');
			console.log('AJAX error');
	  }
	});
}
</script>
{/block}